package zero.tech.games.mj.util;

import zero.tech.games.common.WaterMode;
import zero.tech.games.entity.games.Club;
import zero.tech.games.logic.common.Room;
import zero.tech.games.logic.data.RoomStatus;
import zero.tech.games.mj.data.MjConfig;
import zero.tech.wsnet.controller.LogicController;

public class RoomUtil {

	/**
	 * 准备时检查玩家钱是否足够
	 * @param room
	 * @param logicController
	 * @return
	 */
	public static boolean checkMoneyEnoughNextRound(Room room, LogicController logicController) {
		Club club = room.getClub();
		if(club != null) {
			long gold = logicController.getGold();
			MjConfig mjConfig = (MjConfig) room.getGameConfig();
			int room_status = room.getRoom_status();
			if(room_status == RoomStatus.DEFAULT) {
				Long admission_fee = mjConfig.getAdmission_fee();
				if(gold >= admission_fee) {
					return true;
				}
			}else {
				int water_mode = mjConfig.getWater_mode();
				long need_aa = 0L;
				if(water_mode == WaterMode.AA) {
					//需要预留AA抽水的钱
					need_aa = mjConfig.getWater_num();
				}
				//检查钱是否足够
				long base_score = mjConfig.getBase_score();
				long need = base_score + need_aa;
				if(gold >= need) {
					//钱不够
					return true;
				}
			}
			return false;
		}else {
			return true;
		}
	}
}
